package com.itheima.controller;

import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.QueryPageBean;
import com.itheima.pojo.Result;
import com.itheima.service.CheckGroupService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/checkGroup")
public class CheckGroupController {
    //依赖于service
    @Reference
    private CheckGroupService checkGroupService;

    /**
     * 模糊分页查询
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findCheckGroupByPage.do")
    public Result findCheckGroupByPage(@RequestBody QueryPageBean queryPageBean){
        //调用分页查询的方法
        Result result = checkGroupService.findCheckGroupByPage(queryPageBean);
        return result;
    }

    /**
     * 根据删除检查组
     * @param id
     * @return
     */
    @RequestMapping("/deleteCheckGroupById.do")
    public Result deleteCheckGroupById(@RequestParam String id){
        //System.out.println("前端的传递的id是:"+id);
        //调用分页查询的方法
        Result result = checkGroupService.deleteCheckGroupById(id);
        return result;
    }

    /**
     * 添加检查组
     * @param checkitemIds
     * @param checkGroup
     * @return
     */
    @RequestMapping("/addCheckGroup.do")
    public Result addCheckGroup(@RequestParam("checkitemIds") int[] checkitemIds, @RequestBody CheckGroup checkGroup){
        Result result = checkGroupService.addCheckGroup(checkitemIds,checkGroup);
        return result;
    }

    /**
     * 根据id查询检查组
     * @param id
     * @return
     */
    @RequestMapping("/findCheckGroupById.do")
    public Result findCheckGroupById(@RequestParam String id){
        //调用分页查询的方法
        Result result = checkGroupService.findCheckGroupById(id);
        return result;
    }

    /**
     * 根据检查组的id查询相对应的检查项
     * @param id
     * @return
     */
    @RequestMapping("/findCheckItemIdsByGroupId.do")
    public Result findCheckItemIdsByGroupId(@RequestParam String id){
        Result result = checkGroupService.findCheckItemIdsByGroupId(id);
        return result;
    }

    /**
     * 编辑检查组
     * @param checkitemIds
     * @param checkGroup
     * @return
     */
    @RequestMapping("/updateCheckGroupById.do")
    public Result updateCheckGroupById(@RequestParam("checkitemIds") int[] checkitemIds, @RequestBody CheckGroup checkGroup){
        Result result = checkGroupService.updateCheckGroupById(checkitemIds,checkGroup);
        return result;
    }

    /**
     * 查询所有的检查组
     * @return
     */
    @RequestMapping("/findAllCheckGroup.do")
    public Result findAllCheckGroup(){
        //调用分页查询的方法
        Result result = checkGroupService.findAllCheckGroup();
        return result;
    }

}
